import autoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default function createAutoImport() {
    return [
        autoImport({
            imports: [
                'vue',
                'vue-router',
                {
                    '@/plugins/xl.js': [['default', '$xl']],
                    '@/plugins/dict.js': [['default', '$dict']],
                    '@/store/index.js': [['default', '$store']],
                    '@/layouts/content/FormDialog/FormType.js': [['default', '$formType']],
                    '@/layouts/content/FormDialog/FormVerify.js': [['default', '$formVerify']],
                    '@/layouts/content/FormDialog/FormComputed.js': [['default', '$formComputed']],
                    '@/directive/permission/hasPerm.js': [['default', 'hasPerm']],
                    '@/directive/px-to-rem/px-to-rem.js': [['pxToRemDirective', 'pxToRem'], ['pxToRemDeepDirective', 'pxToRemDeep']],
                }
            ],
            // 用于自定义自动导入的解析逻辑，注意不会自动出现在生成的 auto-imports.d.ts 类型定义文件
            resolvers: [
                ElementPlusResolver({
                    importStyle: 'sass',
                    directives: true
                })
            ],
            // 模板中使用也会自动导入,默认false
            vueTemplate: true,
            viteOptimizeDeps: true,
            // 指令自动导入
            vueDirectives: {
                isDirective: (from) => from.startsWith('@/directive')
            },
            dts: 'vite/autoImport/auto-imports.d.ts',   //类型定义文件的生成（dts）只包含 imports 和目录（dirs）配置中的内容。
            eslintrc: {
                enabled: true,
                filepath: 'vite/autoImport/.eslintrc-auto-import.json',
                globalsPropValue: true
            }
        }),
        Components({
            dirs: ['src/components', 'src/layouts/content'],
            resolvers: [
                ElementPlusResolver()
            ],
            dts: 'vite/autoImport/components.d.ts'
        })
    ]
}
